<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/11/22
 * Time: 15:33
 */
namespace app\index\model;
use think\Model;

class Goods extends Model{
//获取器
    public function getAddtimeAttr($v,$d)
    {
        return date('Y-m-d H:i:s',$v);
    }
    public function getIsShowAttr($v,$d)
    {
        return $v==1?'是':'否';
    }
    public function getIsHotAttr($v,$d)
    {
        return $v==1?'是':'否';
    }
    public function getIsDownAttr($v,$d)
    {
        return $v==1?'是':'否';
    }

//搜索器
    public function searchKeywordsAttr($q,$v,$d)
    {
        $q->where('g.name','like',"%{$v}%");
    }
    public function searchIsShowAttr($q,$v,$d)
    {
        $q->where('g.is_show','=',$v);
    }
    public function searchIsHotAttr($q,$v,$d)
    {
        $q->where('g.is_hot','=',$v);
    }
    public function searchIsDownAttr($q,$v,$d)
    {
        $q->where('g.is_down','=',$v);
    }
    public function searchCidAttr($q,$v,$d)
    {
        $q->where('g.cid','=',$v);
    }


    public static function all($where)
    {
        $list=Goods::alias('g')
            ->join('category c','g.cid=c.id')
            ->field('g.*')
            ->field('c.name cname')
            ->withSearch(array_keys($where),$where)
            ->paginate([
                'list_rows'=>3,
                'query'=>$where
            ]);
        return $list;
    }
}
